//
//  AppStartRequestObject.m
//  woosiiUniversity
//
//  Created by MT on 2017/3/15.
//  Copyright © 2017年 woosiiUniversity. All rights reserved.
//

#import "AppStartRequestObject.h"

@implementation AppStartRequestObject
+ (AppStartRequestObject *)instance
{
    static AppStartRequestObject *appRequest = nil;
    if (appRequest == nil) {
        appRequest = [[self alloc]init];
    }
    return appRequest;
}

- (void)creatOperation{
    [self getAPIRequest];
    
    //创建请求类别数组
    NSMutableArray *RequestTypeArray = [NSMutableArray array];
    NSMutableArray *keyArray = [NSMutableArray array];
    NSMutableArray *dicArray = [NSMutableArray array];
    
//    [keyArray addObject:@"getAPI"];
//    [RequestTypeArray addObject:getAPI];
    NSDictionary *dic = [NSDictionary dictionary];
    [dicArray addObject:dic];
    
    
    // 创建一个队列
    NSOperationQueue *queue = [[NSOperationQueue alloc]init];
    // 设置最大线程数
    queue.maxConcurrentOperationCount = RequestTypeArray.count;
    // 循环创建请求操作
    
    for (int i = 0 ; i < RequestTypeArray.count; i++) {
        NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
            [NetworkManager post:RequestTypeArray[i] parameters:dicArray[i] success:^(id object) {
            } failure:^(NSError *error) {
            }];
        }];
        // 加入到队列中
        [queue addOperation:operation];
    }
    
#pragma mark -- 添加依赖(如需要请求有先后,则要添加依赖)
    //    [operationB addDependency:operationA];
    
}

- (void)getAPIRequest{
    [NetworkManager post:getAPI parameters:nil success:^(id object) {
        [Tool setLocalDataValue:object[@"data"][@"domain"] key:@"serverUrl"];
    } failure:^(NSError *error) {
    }];
}

@end
